﻿using B.S.Procurement.Domain;
using B.S.Procurement.Error;
using B.S.Procurement.Read.Api.Application.Command.ProductsModelCommand;
using MediatR;
using SqlSugar;

namespace B.S.Procurement.Read.Api.Application.CommandHander.ProductsModelCommandHander
{
    public class GetProductsModelCommandHander : IRequestHandler<GetProductsModelCommand, ApiResult<List<ProductsModel>>>
    {
        private readonly IMediator mediator;
        private readonly ISqlSugarClient db;

        public GetProductsModelCommandHander(IMediator mediator, ISqlSugarClient db)
        {
            this.mediator = mediator;
            this.db = db;
        }

        public async Task<ApiResult<List<ProductsModel>>> Handle(GetProductsModelCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<ProductsModel>> result = new ApiResult<List<ProductsModel>>();

            var item = await db.Queryable<ProductsModel>().Where(x => x.Del == false).ToListAsync();

            result.Code = ApiEnum.success;
            result.Msg = "查询产品信息成功";
            result.Data = item;

            return result;
        }
    }
}
